<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Title</title>
    <script src="../js/vue.js"></script>
</head>

<body>
    <div id="app">
        <!-- 将父组件（vue实例）中的数据传给子组件 -->
        <cpn v-bind:cmovies="movies" :cmessage="message"></cpn>
        <!-- 使用默认值 -->
        <cpn></cpn>
    </div>




    <template id="CPN">
        <div>
            <h2>{{cmovies}}</h2>
            <ul>
                <li v-for="item in cmovies">{{item}}</li>
            </ul>
            <h2>{{cmessage}}</h2>
        </div>
    </template>




    <script>
        const cpn = {
            template: '#CPN',
            data() {
                return {

                }
            },
            // props: ['cmovies','cmessage',],
            props: {
                //类型限制
                cmovies: Array,
                cmessage: String,

                //提供一些默认值,如果父组件没有传递数据，则显示默认值
                cmovies: {
                    type: Array,
                    default: ['1', '2', '3', '4'],
                },
                cmessage: {
                    type: String,
                    default: 'default',
                    required: true, //必须要传递这个数据，否则报错
                }
            },
            methods: {

            },
        }





        const vm = new Vue({
            el: '#app',
            data: {
                message: '我是你爹!',
                movies: ['电影1', '电影2', '电影3', '电影4']
            },
            methods: {},
            components: {
                cpn: cpn,


            }
        });
    </script>
</body>

</html>